package com.ee.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.ee.bean.User;
import com.ee.dao.UserDao;
@Component("userDao")
public class UserDaoImpl implements UserDao {
	private HibernateTemplate hibernateTemplate;
	
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	
	@Override
	public void saveUser(User user) {
		hibernateTemplate.save(user);
	}

	@Override
	public void deleteUser(User user) {
		// TODO Auto-generated method stub
		hibernateTemplate.delete(user);
	}

	@Override
	public User findUserById(int id) {
		return hibernateTemplate.get(User.class, id);
	}

	@Override
	public void update(User user) {
		hibernateTemplate.update(user);
	}

	@Override
	public List<User> getUserByNamePwd(String account, String password) {
		String hql = "from User user where account=? and password=?";
		List<User> users = (List<User>)hibernateTemplate.find(hql, new String[]{account, password});
		return users;
	}
	
	@Override
	public List<User> findUserByName(String account) {
		String hql = "from User user where account=?";
		List<User> users = (List<User>)hibernateTemplate.find(hql, new String[]{account});
		return users;
	}

	

	@Override
	public List<User> findOperators() {
		String hql = "from User where auth='operator'";
		List<User> users = hibernateTemplate.find(hql);
		return users;
	}
	@Override
	public List<User> findAllUsers() {
		String hql = "from User";
		List<User> users = hibernateTemplate.find(hql);
		return users;
	}

}
